/*
 * Copyright (c) 2020 - present, Inspur Genersoft Co., Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package io.iec.edp.caf.commons.runtime.config;

import io.iec.edp.caf.commons.runtime.CafEnvironment;
import org.yaml.snakeyaml.Yaml;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;

public class YamlReader {

    public static Map<String,Object> getYaml(String filePath){
        Map<String,Object> yamlContent = new HashMap<>();
        File yamlFile = new File(filePath);
        InputStream input = null;
        if(yamlFile.exists()){
            try{
                input = new FileInputStream(yamlFile);
                Yaml yaml = new Yaml();
                yamlContent = yaml.load(input);

                //从yaml中获取到相关配置
                if(yamlContent.containsKey("msu-config")){

                }
            }catch (Throwable e){
                throw new RuntimeException(e);
            }finally {
                try{
                    if(input!=null){
                        input.close();
                    }
                }catch (Throwable e){
                    throw new RuntimeException("Close InputStream Error",e);
                }
            }
        }
        return yamlContent;
    }

}
